#include "chatserver.hpp"
#include "chatservice.hpp"
#include <memory>
#include <string>
#include <signal.h>

// 处理服务器收到CTRL+c退出的信号
void resetHandler(int)
{
    ChatService::instance()->reset();
    exit(-1);
}

void Usage()
{
    std::cout << "\n\tcommand invalid, example ./chatServer 127.0.0.1 8081\n";
    exit(-1);
}

int main(int argc, char **argv)
{
    if(argc < 3)
    {
        Usage();
    }

    signal(SIGINT, resetHandler);
    EventLoop loop;
    InetAddress addr(string(argv[1]), atoi(argv[2]));
    std::unique_ptr<ChatServer> svr(new ChatServer(&loop, addr, "ChatServer"));
    
    svr->start();
    loop.loop();
    return 0;
}